package demo.spring.test180315;

import demo.spring.UnitTestBase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Author: tyzhang
 * @Description:
 * @Date: Created in 23:01 2018/3/15
 */
@RunWith(BlockJUnit4ClassRunner.class)
public class TestInjectionTest extends UnitTestBase {
    public TestInjectionTest() {
        super("classpath:spring-injection.xml");
    }

    @Test
    public void testSetter1(){
        InjectionService service = super.getBean("injectionService");
        service.save("这是要保存的数据");
    }

    @Test
    public void testSetter() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-injection.xml");
        InjectionService injectionService = (InjectionService) applicationContext.getBean("injectionService");
        injectionService.save("这是要保存的数据");
    }

    @Test
    public void constructor(){
        InjectionService service=super.getBean("injectionService");
        service.save("这是要保存的数据");
    }

    @Test
    public void constructor1(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring-injection.xml");
        InjectionService injectionService = (InjectionService) applicationContext.getBean("injectionService");
        injectionService.save("这是要保存的数据");
    }
}
